package Chat_program_Rasmus;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.net.*;
import java.awt.EventQueue;
import java.awt.event.*;
import java.io.IOException;
import java.io.PrintWriter;

public class Server_GUI2 {
	
	// Globals
	
	private static Client ChatClient;
	public static String UserName = "Anonymous";
		
	// Login window
	
	private static JPanel P_LogIn;
	private static JTextField textfield_username;
	private static JPasswordField password;
	private static JLabel label_username;
	private static JLabel label_password;
	private static JButton button_login;
	private static JButton button_new_user;
	private static JButton button_cancel;
	
	public static JFrame LogInWindow;
	
	
	
	//------------------------------------------------------------------------------------
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					
					UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
			
					BuildLogInWindow();
					LogInWindow.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

	}
	
		
	//------------------------------------------------------------------------------------
	
	public static void ConfigureLogInWindow()
	{
		
		LogInWindow.setSize(238,160);
		LogInWindow.getContentPane().setLayout(null);
			
		P_LogIn = new JPanel();
		P_LogIn.setBorder(new EmptyBorder(5, 5, 5, 5));
		
		P_LogIn.setLayout(null);
		
		label_username = new JLabel("Username");
		label_username.setBounds(10, 10, 80, 20);
		label_username.setHorizontalAlignment(SwingConstants.LEFT);
		P_LogIn.add(label_username);
		
		label_password = new JLabel("Password");
		label_password.setBounds(10, 40, 80, 20);
		P_LogIn.add(label_password);
		
		button_login = new JButton("Login User");
		button_login.setBounds(10, 70, 99, 51);
		button_login.setEnabled(true);	
		P_LogIn.add(button_login);
		
		
		button_new_user = new JButton("New User");
		button_new_user.setBounds(120, 70, 100, 20);
		button_new_user.setEnabled(false);	
		P_LogIn.add(button_new_user);
		
		button_cancel = new JButton("Cancel");
		button_cancel.setBounds(120, 101, 100, 20);
		button_cancel.setEnabled(true);	
		P_LogIn.add(button_cancel);
		
		textfield_username = new JTextField();
		textfield_username.setBounds(100, 10, 120, 20);
		P_LogIn.add(textfield_username);
		textfield_username.setColumns(10);
		
		password = new JPasswordField();
		password.setBounds(100, 40, 120, 20);
		password.setColumns(10);
		P_LogIn.add(password);
		LogInWindow.setContentPane(P_LogIn);
		
	}

	//--------------------------------------------------------------------------------------------
	
		public static void BuildLogInWindow()
		{
			LogInWindow = new JFrame();
			LogInWindow.setTitle("Login Window");
			LogInWindow.setSize(400, 100);
			LogInWindow.setLocation(250, 200);
			LogInWindow.setResizable(false);
			LogInWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			LogInWindow.setBounds(100, 100, 238, 160);
				
			ConfigureLogInWindow();	
		}
	
	
	//--------------------------------------------------------------------------------------------
	
		public static void ACTION_P_LogIn()
		{
			if (!textfield_username.getText().equals(""))
			{
				UserName = textfield_username.getText().trim();
				LogInWindow.dispose();
				
			}
			else
			{ 
				JOptionPane.showMessageDialog(null, "please enter a name!");		
			}
			
		}
}
